"""
1. 设置一个dict
2. 遍历数组nums
3. 如果当前的num值不在dict中就将target-num的索引存入d中
4. 存在的话就返回两个索引值组成的list
"""


class Solution:
    def twoSum(self, nums, target):
        """
        :type nums: List[int]
        :type target: int
        :rtype: List[int]
        """
        d = {}
        for i, num in enumerate(nums):
            if num in d:
                return [d[num], i]
            else:
                d[target - num] = i


def test_towSum():
    nums = [2, 7, 11, 15]
    assert [0, 1] == Solution().twoSum(nums, 9)
